package com.AdvancedDemos.接口.学生信息接口案例;

import java.util.ArrayList;

public class StudentOperatorImpl2 implements StudentOperator {

    /**
     * 打印全班学生信息,还额外打印了男女生人数,总人数
     *
     * @param students
     */
    @Override
    public void printAllInfo(ArrayList<Student> students) {
        System.out.println("----全班全部学生信息如下----");
        int countMale = 0, countFemale = 0;
        for (int i = 0; i < students.size(); i++) {
            Student temp = students.get(i);
            System.out.println("姓名:" + temp.getName() + ",性别:" + temp.getGender() + ",成绩:" + temp.getScore());
            if (temp.getGender() == '男') {
                countMale++;
            } else {
                countFemale++;
            }
        }
        System.out.println("男生人数是:" + countMale + ",女生人数是:" + countFemale);
        System.out.println("班级总人数是:" + (countFemale + countMale));
        System.out.println("------------------------");
    }

    /**
     * 打印除去最高分和最低分后的平均分
     *
     * @param students
     */
    @Override
    public void printAverageScore(ArrayList<Student> students) {
        double allScore = 0.0;
        double max = students.get(0).getScore();
        double min = students.get(0).getScore();

        for (int i = 0; i < students.size(); i++) {
            Student temp = students.get(i);
            if (temp.getScore() > max) {
                max = temp.getScore();
            }
            if (temp.getScore() < min) {
                min = temp.getScore();
            }
            allScore += temp.getScore();
        }
        System.out.println("学生的最高分是:" + max);
        System.out.println("学生的最低分是:" + min);
        System.out.println("去掉最高分最低分平均分是:" + (allScore - max - min) / (students.size() - 2));
    }
}
